// pages/lists/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zhi:'',
    title11:"",
    content11:" ",
    author11:" ",

    title12:"",
    content12:" ",
    author12:" ",

    title13:"",
    content13:" ",
    author13:" ",

    title14:"",
    content14:" ",
    author14:" ",

    title15:"",
    content15:" ",
    author15:" ",

    title16:"",
    content16:" ",
    author16:" ",

    title17:"",
    content17:" ",
    author17:" ",

    title18:"",
    content18:" ",
    author18:" ",

    title19:"",
    content19:" ",
    author19:" ",

    title20:"",
    content20:" ",
    author20:" ",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      zhi:wx.getStorageSync('zhi')
    })
    
    console.log(this.data.zhi);   

     var body;
    var that = this;
    
    wx.request({
      url: 'https://api.tianapi.com/txapi/poetries/index?key=2ed99a821e40641cc2d133e6de15cf52&word='+this.data.zhi+'&num=10', 
      success: function (res) {
       
        if(res.data.code == 200){
          body = res.data.newslist;
          var temp = JSON.stringify(body);
          console.log(temp);
         
          if(that.data.zhi.length<=4){
            that.setData({
              title11:res.data.newslist[0].title,
              author11:res.data.newslist[0].author,
              content11: res.data.newslist[0].content,
  
              title12:res.data.newslist[1].title,
              author12:res.data.newslist[1].author,
              content12: res.data.newslist[1].content,
  
              title13:res.data.newslist[2].title,
              author13:res.data.newslist[2].author,
              content13: res.data.newslist[2].content,
  
              title14:res.data.newslist[3].title,
              author14:res.data.newslist[3].author,
              content14: res.data.newslist[3].content,
  
              title15:res.data.newslist[4].title,
              author15:res.data.newslist[4].author,
              content15: res.data.newslist[4].content,
  
              title16:res.data.newslist[5].title,
              author16:res.data.newslist[5].author,
              content16: res.data.newslist[5].content,
  
              title17:res.data.newslist[6].title,
              author17:res.data.newslist[6].author,
              content17: res.data.newslist[6].content,
  
              title18:res.data.newslist[7].title,
              author18:res.data.newslist[7].author,
              content18: res.data.newslist[7].content,
  
              title19:res.data.newslist[8].title,
              author19:res.data.newslist[8].author,
              content19: res.data.newslist[8].content,
  
              title20:res.data.newslist[9].title,
              author20:res.data.newslist[9].author,
              content20: res.data.newslist[9].content,
  
            
            })
          }else{
            that.setData({
              title11:res.data.newslist[0].title,
              author11:res.data.newslist[0].author,
              content11: res.data.newslist[0].content
            })
            
          }
          
        
      }else{
          that.setData({
            content: res.data.msg
          }) 
      }
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})